package com.example.hemengqi


import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class StudentAdapter(private val studentList: List<Student>) :
    RecyclerView.Adapter<StudentAdapter.StudentViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): StudentViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.student_item, parent, false)
        return StudentViewHolder(view)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: StudentViewHolder, position: Int) {
        val student = studentList[position]
        holder.tvStudentId.text = "学号: ${student.id}"
        holder.tvStudentName.text = "姓名: ${student.name}"
        holder.tvStudentGender.text = "性别: ${student.gender}"
        holder.tvStudentClass.text = "班级: ${student.className}"
    }

    override fun getItemCount(): Int {
        return studentList.size
    }

    class StudentViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val tvStudentId: TextView = itemView.findViewById(R.id.tvStudentId)
        val tvStudentName: TextView = itemView.findViewById(R.id.tvStudentName)
        val tvStudentGender: TextView = itemView.findViewById(R.id.tvStudentGender)
        val tvStudentClass: TextView = itemView.findViewById(R.id.tvStudentClass)
    }
}